package monopoli.communication;


import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Marco
 */
public class MapTypeIdMessage {


    private ConcurrentHashMap<Integer,Long> map = null;

    

    public void initialize() {


        map = new ConcurrentHashMap<Integer,Long>();

        map.put(new Integer(Message.TYPE_TOKEN), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_MOVE_PEDINA), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_BUY_PROPERTY), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_BUILD_BUILDING), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_PAYMENT), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_WITHDRAWAL), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_MORTGAGE), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_END_GAME), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_AUCTION_STARTED), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_DEATH_PLAYER), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_GET_PROPERTY), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_PEDINA), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_NAME), new Long(0));
        map.put(new Integer(Message.SUBTYPE_NOTIFY_MSG), new Long(0));

        
    }

    synchronized public void update(int key, long val) {
        map.replace(new Integer(key), new Long(val));
    }

    public long getMaxVal() {

        Iterator<Long> it = map.values().iterator();
        long val = 0;

        while ( it.hasNext() ) {
            Long t = it.next();

            if ( val < t.longValue() )
                    val = t.longValue();

        }

        return val;

    }

    public long getByType(int key) {
        return map.get(key).longValue();
    }

}
